const app = getApp();
Page({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: { 

    curImgUrl: '',
    srcImg:[],
    srcList: [
      "img/1.png", 
      "img/1.png",
      "img/1.png"],
    curImgSrc: '',
    count1 : 0,
    system:['安卓','IOS'],
    objectsystem: [
      {
        id: 0,
        name: '安卓',
        id: 1,
        name: 'IOS'
      }
    ],
    game: ['王者荣耀'],
    objectGame: [
      {
        id: 0,
        name: '王者荣耀'
      }
    ],
    platform: ['QQ', '微信'],
    objectPlatform: [
      {
        id: 0,
        name: 'QQ',
        id: 1,
        name: '微信'
      }
    ],
     rank: ['秩序白银', '荣耀黄金', '尊贵铂金', '永恒钻石Ⅴ', '永恒钻石Ⅳ~Ⅲ', '永恒钻石Ⅱ~Ⅰ', '至尊星耀Ⅴ~Ⅲ', '至尊星耀Ⅱ~Ⅰ', '最强王者1~10', '最强王者11~20', '最强王者21~25', '最强王者26~30', '最强王者31~35', '最强王者36~40', '最强王者41~45', '最强王者46~50', '最强王者51~100'],
    objectRank: [
      {
        id: 0,
        name: '秩序白银',
        id: 1,
        name: '荣耀黄金',
        id: 2,
        name: '尊贵铂金',
        id: 3,
        name: '永恒钻石Ⅴ',
        id: 4,
        name: '永恒钻石Ⅳ~Ⅲ',
        id: 5,
        name: '永恒钻石Ⅱ~Ⅰ',
        id: 6,
        name: '至尊星耀Ⅴ~Ⅲ',
        id: 7,
        name: '至尊星耀Ⅱ~Ⅰ',
        id: 8,
        name: '最强王者1~10',
        id: 9,
        name: '最强王者11~20',
        id: 10,
        name: '最强王者21~25',
        id: 11,
        name: '最强王者26~30',
        id: 12,
        name: '最强王者31~35',
        id: 13,
        name: '最强王者36~40',
        id: 14,
        name: '最强王者41~45',
        id: 15,
        name: '最强王者46~50',
        id: 16,
        name: '最强王者51~100'
      }
    ],

    // positio: ['1', '2', '3', '4', '5'],
    // objectPositio: [
    //   {
    //     id: 0,
    //     name: '1',
    //     id: 1,
    //     name: '2',
    //     id: 2,
    //     name: '3',
    //     id: 3,
    //     name: '4',
    //     id: 4,
    //     name: '5'
    //   }
    // ],
    index1: 0,
    index2: 0,
    index3: 0,
    index4: '',   
    index7: 0,
    index5:'',
    index6:'',
  },

  

  /**
   * 组件的方法列表
   */
    bindRankChange: function (e) {
      this.setData({
        index1: e.detail.value
      })
    },
    bindPlatformChange: function (e) {
      this.setData({
        index2: e.detail.value
      })
    },
  
    bindGameChange: function (e) {
      this.setData({
        index3: e.detail.value
      })
    },
    bindposition: function (e) {
      this.setData({
        index4: e.detail.value
      })
    },
    bindid: function (e) {
      this.setData({
        index5: e.detail.value
      })
    },
    bindinf: function (e) {
      this.setData({
        index6: e.detail.value
      })
    },
  bindsystem: function (e) {
    this.setData({
      index7: e.detail.value
    })
  },


  chooseImg: function (e) {
    var that = this;
    console.log(e);
    var index = e.currentTarget.dataset.index;
    var srcPath = "srcList[" + index + "]";
    console.log(srcPath);
    wx.chooseImage({
      count: 1,
      sizeType: ['compressed'],
      sourceType: ['album'],
      success(res) {
        console.log(res)
        var tempFilePaths = res.tempFilePaths
        that.data.srcImg[that.data.count1] = tempFilePaths[0]
        that.data.count1++
        that.setData({
          [srcPath]: tempFilePaths[0],
          curImgSrc: tempFilePaths[0],
         
        }),
          console.log(that.data)
      //  wx.uploadFile({
      //    url: 'https://www.enjoyyz.com:8443/yinzuo/join', //仅为示例，非真实的接口地址
      //    filePath: that.data.curImgSrc,
      //    name: 'myfile',
      //    formData: {
      //     //  level_code: rank,
      //     //  platform: platform,
      //     //  game_choice: game,
      //     //  location: positio,
      //     //  // userId: userid,
      //     //  userId: '216619',
      //     //  desc: index6,
      //     //  system: index7,
      //     //  nickname: index5
      //    },
      //    success: function(res) {},
      //    fail: function(res) {},
      //    complete: function(res) {},
      //  })
      }
    })
  },
  formSubmit: function (event) {
    var that = this;
    var index1 = this.data.index1;
    var index2 = this.data.index2;
    var index4 = this.data.index4;
    var index3 = this.data.index3;
    var index5 = this.data.index5;
    var index6 = this.data.index6;
    var index7 = this.data.index7;
    // var sum = this.data.sum[index1];
    var rank = index1*1+1;
    var platform = this.data.platform[index2];
    var game = this.data.game[index3];
    // var positio = this.data.positio[index4];
    var userid = app.globalData.userid;
    for(var i = 0;i<3;i++){
      wx.uploadFile({
        url: 'https://www.enjoyyz.com:8443/yinzuo/join', //仅为示例，非真实的接口地址
        filePath: that.data.srcImg[i],
        // filePath: that.data.curImgSrc,
        // filePath: that.data.curImgSrc,
        name: 'myfile',
        formData: {
          level_code: rank,
          platform: platform,
          game_choice: game,
          location: index4,
          userId: userid,
          // userId: '216619',
          desc: index6,
          system: index7*1+1,
          nickname: index5
        },
        success(res) {
          const data = res.data;
          console.log(res, 'aaaaaaaaaaaaa')
          console.log(rank, 'rank')
          console.log(that.data.curImgSrc, ' that.data.curImgSrc')
          console.log(index7 * 1 + 1,'index7*1+1')
          wx.showToast({
            title: '认证成功',
          })
          //do something
        },
        fail(res) {
          const data = res.data;
          console.log(res, 'aaaaaaaaaaaaa')
          wx.showToast({
            title: '认证失败',
          })
          //do something
        }
      })
      wx.switchTab({
        url: "/pages/homeTab/homeTab",
        success: function () {
          console.log("jump success")
        },
        fail: function () {
          console.log("jump fail")
        },
        complete: function () {
          console.log("jump complete")
        }
      });
    }
  
  }
})
